package org.niux.AutoLoginQQ.timer;

import java.util.List;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.niux.AutoLoginQQ.VO.QQNumVO;
import org.niux.AutoLoginQQ.common.Constant;
import org.niux.AutoLoginQQ.operate.LoginQQ;
import org.niux.AutoLoginQQ.ui.Main;

/**
 * 
 * Copyright (c) 2009,niux<br>
 * All rights reserved.<br>
 * 
 * 文件名称：ScanTaskTimer.java<br>
 * 摘    要：定时登录定时器<br>
 * <br>
 * 当前版本：<br>
 * 作    者：mingxian Email: <a href="mailto:liangmingxian@gmail.com">liangmingxian@gmail.com</a><br>
 * 完成日期：@since 2012-9-12<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 22, 2009<br>
 */
public class TimingLoginTimer extends TimerTask {
	
	private Log log = LogFactory.getLog(this.getClass());
	
	private List<QQNumVO> qqList;
	
	private Main gui;
	
	public TimingLoginTimer(Main gui,List<QQNumVO> qqList) {
		super();
		this.gui = gui;
		this.qqList = qqList;
	}

	@Override
	public void run() {
		log.debug("==========定时登录任务执行=============");
		// 执行登录操作
		Thread autoLoginThread = new Thread(new Runnable() {
			public void run() {
				LoginQQ loginQQ = new LoginQQ(gui);

				Constant.SCAN_TASK_TIMER_LOGGER = true;

				loginQQ.login(qqList);

				Constant.SCAN_TASK_TIMER_LOGGER = false;

				if (Constant.AUTO_SHUTDOWN) {
					Constant.SHUTDOWN = true;
				}
			}
		});

		autoLoginThread.start();

		Constant.THREAD_POOL.add(autoLoginThread);
	}

}
